package connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;

public class ConnectionToDB {
	public Logger log = Logger.getLogger(ConnectionToDB.class.getName());
	 // JDBC driver name and database URL
	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
	static final String DB_URL = "jdbc:mysql://localhost:3306/monitoryourmoneydb";

	//  Database credentials
	static final String USER = "root";
	static final String PASS = "server";
	Connection conn = null;
	
	public Connection getConnection(){

		//STEP 2: Register JDBC driver
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(DB_URL, USER, PASS);
			log.info("connect");
		} catch (ClassNotFoundException e) {
			log.info("kelas hilang");
			e.printStackTrace();
		} catch (SQLException e) {
			log.info("db tidak ada");
			e.printStackTrace();
		}
		return conn;
	}
}
